package name.marz.to.go.ahg.mufgbk.executer;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import name.marz.to.go.ahg.common.util.HttpUtil;
import name.marz.to.go.ahg.core.AutoGetterHttpClient;
import name.marz.to.go.ahg.core.Parameters;
import name.marz.to.go.ahg.core.executer.AbstractPostExecuter;
import name.marz.to.go.ahg.core.responsehandler.DocumentResponseHandler;

import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.nodes.Document;

public class MUFGbkLogoutExecuter extends AbstractPostExecuter<Document> {
	private static final String FORM_NAME="MainForm";
	private ResponseHandler<Document> handler = null;
	private Document srcDoc;
	
	public MUFGbkLogoutExecuter(URI uri, AutoGetterHttpClient client,
			Document doc) {
		super(uri, client, "ログアウト");
		this.handler = new DocumentResponseHandler(client.getDefaultCharset());
		this.srcDoc = doc;
		super.uri = HttpUtil.createURISafety("https://direct11.bk.mufg.jp/ib/dfw/APL/bnkib/banking");
	}

	@Override
	protected List<NameValuePair> getRequestParameters() {
		Parameters p = HttpUtil.getParametersFromFormTag(srcDoc,FORM_NAME);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("_TRANID", "AD001_022"));
		params.add(new BasicNameValuePair("_TARGET", ""));
		params.add(new BasicNameValuePair("_FRAMID", ""));
		params.add(new BasicNameValuePair("_TARGETWINID", ""));
		params.add(p.getNameValuePair("_LUID"));
		params.add(p.getNameValuePair("_SENDTS"));
		params.add(p.getNameValuePair("_PAGEID"));
		params.add(p.getNameValuePair("_WINID"));
		params.add(p.getNameValuePair("_SUBINDEX"));
	
		return params;
	}

	@Override
	protected ResponseHandler<Document> getResponseHandler() {
		return handler;
	}

}
